package top.xiaoazi.futureletterserver.utils;

import java.text.SimpleDateFormat;
import java.util.Calendar;

/**
 * 时间工具类
 */
public class TimeUtils {
    public static final String SECOND = "second";
    public static final String MINUTE = "minute";
    public static final String HOUR = "hour";

    public static Long currentTimeMillis(String level) {
        return switch (level) {
            case SECOND -> System.currentTimeMillis() / 1000;
            case MINUTE -> System.currentTimeMillis() / 1000 / 60;
            case HOUR -> System.currentTimeMillis() / 1000 / 60 / 60;
            default -> System.currentTimeMillis();
        };
    }

    public static Long currentTimeMillis() {
        return System.currentTimeMillis();
    }

    public static String getTimeString() {
        Calendar calendar = Calendar.getInstance();
        // 格式化当前时间为字符串，精确到分钟
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return dateFormat.format(calendar.getTime());
    }
    public static String getTimeString(String temp) {
        Calendar calendar = Calendar.getInstance();
        SimpleDateFormat dateFormat = new SimpleDateFormat(temp);
        return dateFormat.format(calendar.getTime());
    }
}
